//搜索
function projecthousetypeList(init){
	if(init==1)$("#searchForm .pageNum").val(1);	
	JY.Model.loading();
	JY.Ajax.doRequest("searchForm",jypath +'/estate/projectHouseType/list',null,function(data){
		    $("#baseTable tbody").empty();
		     //分页对象
        	 var page=data.obj;
        	 //权限按钮
        	 //var permitBtn=obj.permitBtn;
        	 var permitBtn=new Array();
        	 var objList = $("#permitBtnList").html();
        	 objList=JSON.parse(objList);
        	 for(ob in objList){
        		 if(objList[ob].permission=='estate:projectHouseType:view'){
        			 permitBtn.push({name:"查看",btnFun:"projecthousetypeView",icon:"icon-zoom-in color-purple"});
        		 }else if(objList[ob].permission=='estate:projectHouseType:edit'){
        			 permitBtn.push({name:"修改",btnFun:"projecthousetypeToEdit",icon:"icon-edit color-blue"});
        		 }else if(objList[ob].permission=='estate:projectHouseType:delete'){
        			 permitBtn.push( {name:"删除",btnFun:"projecthousetypeDel",icon:"icon-remove-sign color-red"});
        		 }
        	 }
        	 
        	 
        	 //数据集合
        	 var results=page.rows;
        	 //分页数据
         	 var pageNum=page.pageNumber,pageSize=page.pageSize,totalRecord=page.total;
        	 var html="";
    		 if(results!=null&&results.length>0){
        		 var leng=(pageNum-1)*pageSize;//计算序号
        		 for(var i = 0;i<results.length;i++){
            		 var l=results[i];
            		 html+="<tr>";
            		 //html+="<td class='center'><label> <input type='checkbox' name='ids' value='"+l.id+"' class='ace' /> <span class='lbl'></span></label></td>";
            		 html+="<td class='center hidden-480'>"+(i+leng+1)+"</td>";
            		 html+="<td class='center'>"+JY.Object.notEmpty(l.houseTypeName)+"</td>";
            		 html+="<td class='center'>"+JY.Object.notEmpty(l.projectName)+"</td>";
            		 html+="<td class='center'>"+JY.Object.notEmpty(l.billingArea)+"</td>";
            		 html+="<td class='center'>"+JY.Object.notEmpty(l.insideBuildingArea)+"</td>";
            		 html+="<td class='center'>"+JY.Object.notEmpty(l.useArea)+"</td>";
            		 var fx=l.roomNum+"室"+l.officeNum+"厅"+l.guardNum+"卫";
            		 html+="<td class='center'>"+JY.Object.notEmpty(fx)+"</td>";
            		 html+="<td class='center'>"+JY.Object.notEmpty(l.hasImg)+"</td>";
            		 html+=JY.Tags.setFunction(l.id,permitBtn);
            		 html+="</tr>";		 
            	 } 
        		 $("#baseTable tbody").append(html);
        		 JY.Page.setPage("searchForm","pageing",pageSize,pageNum,totalRecord,"projecthousetypeList");
        	 }else{
        		html+="<tr><td colspan='10' class='center'>没有相关数据</td></tr>";
        		$("#baseTable tbody").append(html);
        		$("#pageing ul").empty();//清空分页
        	 }	
 	 
    	 JY.Model.loadingClose();
	 });
}
//跳转新增
function projecthousetypeToAdd(){
   var projectId=$("#projectId").val();
   var url=jypath+"/estate/projectHouseType/toAdd?projectId="+projectId;
   window.location.href=url;
}

function projecthousetypeBack(){
	   var projectId=$("#projectId").val();
	   var url=jypath+"/estate/projectHouseType/index?projectId="+projectId;
	   window.location.href=url;
}

function backProjectDetail(){
    var projectId=$("#projectId").val();
	var url=jypath+"/estate/treeComponent/index?projectId="+projectId;
	window.location.href=url;
}

//新增
function projecthousetypeAdd(){
	 if(JY.Validate.form("projectHouseTypeForm")){
		 var id=$("#projectHouseTypeId").val();
		 var url="/estate/projectHouseType/add";
		 if(id!=null && id!=""){
			 url="/estate/projectHouseType/edit";
		 }
		 initImageUrl();
		 $("#jyLoading").removeClass("hide");
		 JY.Ajax.doRequest("projectHouseTypeForm",jypath +url,null,function(data){	
			 $("#jyLoading").addClass("hide");
        	JY.Model.info(data.resMsg,function(){projecthousetypeBack();});    
		 }); 
	 }
}


//获取图片url字符串用;隔开
function initImageUrl(){
	var urlStr="";
	var divName="house_type_img_div";
	$("#"+divName+" img").each(function(index,obj){
		var url=$(obj).attr("src");
		if(index==0){
			urlStr=url;
		}else{
			urlStr=urlStr+";"+url;
		}
	});
	$("#houseTypeUrls").val(urlStr);
}

//新增
function projecthousetypeEdit(){
	 if(JY.Validate.form("projectHouseTypeForm")){
		 $("#jyLoading").removeClass("hide");
		 JY.Ajax.doRequest("projectHouseTypeForm",jypath +"/estate/projectHouseType/edit",null,function(data){	
			 $("#jyLoading").addClass("hide");
        	JY.Model.info(data.resMsg,function(){projecthousetypeBack();});    
		 }); 
	 }
}
//修改
function projecthousetypeToEdit(id){
	window.location.href=jypath+'/estate/projectHouseType/toEdit?id='+id;
}
//查看
function projecthousetypeView(id){
	window.location.href=jypath+'/estate/projectHouseType/view?id='+id;
}
//删除
function projecthousetypeDel(id){
	JY.Model.confirm("请再次确认是否删除该户型数据吗？",function(){	
		JY.Ajax.doRequest(null,jypath+'/estate/projectHouseType/delete',{id:id},function(data){
			JY.Model.info(data.resMsg,function(){projecthousetypeList(1);});
		});
	});
}

function showImg(obj){
	var checkImg = $(obj).attr("src");
  	var array = new Array();
  	var parentId =  $(obj).parent().parent().attr("id");
  	array.push({ url:checkImg,caption: getFileName(checkImg),options:{side:'left', maxWidth:500}});
  	var allImg = $("#"+parentId+ " .imgblock img");
 	for(var i=0;i<allImg.length;i++){
		if(allImg.eq(i).attr("src")!=checkImg){
			array.push({ url:allImg.eq(i).attr("src") , caption: getFileName(allImg.eq(i).attr("src")),options:{side:'left', maxWidth:500}});
 		}
 	}
 	Strip.show(array);
}

function getFileName(ftpUrl){
	var fileName = ftpUrl.substring(ftpUrl.indexOf("=")+1,ftpUrl.length);
	var aLink = replaceFileUrl(ftpUrl);
	var abtn = "<a href='${jypath}/common/file/downloadFile"+aLink+"'>"+fileName+"</a>";
	return abtn;
}

function replaceFileUrl(ftpUrl){
	if(ftpUrl==null||ftpUrl==""){
		return ftpUrl;
	}
	//取得文件明
	var fileName=ftpUrl.substring(ftpUrl.indexOf("?")+1,ftpUrl.length);
	ftpUrl=ftpUrl.replace(new RegExp("/","gm"),"?");  
	ftpUrl=ftpUrl.substring(0,ftpUrl.indexOf("?fileName="));
	return "?fileUrl="+ftpUrl+"&"+fileName;
}
